package com.example.myapplication9;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.StringTokenizer;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Button botton8 = findViewById(R.id.button8);//选择排序
        Button botton9 = findViewById(R.id.button9);//插入排序
        Button botton11 = findViewById(R.id.button11);//冒泡排序
        Button botton12 = findViewById(R.id.button12);//归并排序
        Button botton13 = findViewById(R.id.button13);//快速排序
        Button botton14 = findViewById(R.id.button14);//希尔排序
        Button botton15= findViewById(R.id.button15);//堆排序
        Button botton16 = findViewById(R.id.button16);//二叉查找树排序
        final EditText editText = findViewById(R.id.editText7);
        final EditText editText1 = findViewById(R.id.editText8);
        botton8.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText.getText().toString());
                Integer[] ant = new Integer [8];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Integer.parseInt(Tokenizer.nextToken());
                    a++;
                }
                Sorting ab=new Sorting();
                Sorting.selectionSort(ant);
                String result="";
                for(Integer c:ant)
                {
                    result+=c+" ";
                }
                editText1.setText(result );
            }

        });
        botton9.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText.getText().toString());
                Integer[] ant = new Integer [8];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Integer.parseInt(Tokenizer.nextToken());
                    a++;
                }
                Sorting ab=new Sorting();
                Sorting.insertionSort(ant);
                String result="";
                for(Integer c:ant)
                {
                    result+=c+" ";
                }
                editText1.setText(result );
            }

        });
        botton11.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText.getText().toString());
                Integer[] ant = new Integer [8];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Integer.parseInt(Tokenizer.nextToken());
                    a++;
                }
                Sorting ab=new Sorting();
                Sorting.bubbleSort(ant);
                String result="";
                for(Integer c:ant)
                {
                    result+=c+" ";
                }
                editText1.setText(result );
            }

        });
        botton12.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText.getText().toString());
                Integer[] ant = new Integer [8];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Integer.parseInt(Tokenizer.nextToken());
                    a++;
                }
                Sorting ab=new Sorting();
                Sorting.mergeSort(ant);
                String result="";
                for(Integer c:ant)
                {
                    result+=c+" ";
                }
                editText1.setText(result );
            }

        });
        botton13.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText.getText().toString());
                Integer[] ant = new Integer [8];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Integer.parseInt(Tokenizer.nextToken());
                    a++;
                }
                Sorting ab=new Sorting();
                Sorting.quickSort(ant);
                String result="";
                for(Integer c:ant)
                {
                    result+=c+" ";
                }
                editText1.setText(result );
            }

        });
        botton14.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText.getText().toString());
                Integer[] ant = new Integer [8];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Integer.parseInt(Tokenizer.nextToken());
                    a++;
                }
                Sorting ab=new Sorting();
                Sorting.shellSort(ant);
                String result="";
                for(Integer c:ant)
                {
                    result+=c+" ";
                }
                editText1.setText(result );
            }

        });
        botton15.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText.getText().toString());
                Integer[] ant = new Integer [8];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Integer.parseInt(Tokenizer.nextToken());
                    a++;
                }
                Sorting ab=new Sorting();
                Sorting.heapSort(ant);
                String result="";
                for(Integer c:ant)
                {
                    result+=c+" ";
                }
                editText1.setText(result );
            }

        });
        botton16.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText.getText().toString());
                Integer[] ant = new Integer [8];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Integer.parseInt(Tokenizer.nextToken());
                    a++;
                }
                Sorting ab=new Sorting();
                Sorting.binarySearchTreeSort(ant);
                String result="";
                for(Integer c:ant)
                {
                    result+=c+" ";
                }
                editText1.setText(result );
            }

        });







    }
}
